<?php

class Client extends FaceintegrationBaseModel {

    public $logo;

    public static function getElementById($nid) {
        $node = node_load($nid);
        if ($node !== FALSE)
            return Client::toModel($node);
        return NULL;
    }

    public static function getElementsByCategory($tid = NULL) {
        if ($tid == NULL) {
            $current_page = isset($_GET['page']) ? intval($_GET['page']) : 1;
            $query = new EntityFieldQuery();
            $queryResult = $query->entityCondition('entity_type', 'node')
                    ->propertyCondition('type', 'clients')
                    ->propertyOrderBy('created', 'DESC')
                    ->range($from, $limit)
                    ->execute();
        }
        $result = array();
        if (isset($queryResult['node'])) {
            foreach ($queryResult['node'] as $key => $value) {
                $model = Client::getElementById($key);
                if ($model != NULL)
                    $result[] = $model;
            }
        }
        return $result;
    }

    public static function toModel($node) {
        $model_client = new Client();
        $logo_client = field_get_items('node', $node, 'field_client_logo');
        if (count($logo_client) > 0)
            $model_client->logo = file_create_url($logo_client[0]['uri']);
        return $model_client;
    }

    public static function selectClient() {
        $query = db_select('node_type', 'cl')
                        ->condition('cl.type', 'clients')
                        ->fields('cl', array('description'))
                        ->execute()->fetchField();
        return $query;
    }
    public static function PaggingClients(){
        $page=$_GET['page'];
        $row=9;
        $trasivite= 5;
        $sql="SELECT COUNT(*) AS total FROM field_revision_field_client_logo";
        $start=$page*$row;
        $sql="SELECT * FROM field_revision_field_client_logo LIMIT ".$start.",".$row."";
        var_dump($total); die();
            
        
    }

  

}

?>
